package initialize

import (
	"github.com/gin-gonic/gin"
	"liuche17.cn/go-blog/server/global"
	"liuche17.cn/go-blog/server/middleware"
	"liuche17.cn/go-blog/server/router"
)

// Routers 初始化总路由
func Routers() *gin.Engine {
	Router := gin.New()
	Router.Use(middleware.CustomRecovery())
	// 如若是 debug 模式则使用 gin 的默认日志
	if gin.Mode() == gin.DebugMode {
		Router.Use(gin.Logger())
	}

	systemRouter := router.RouterGroupApp.SystemRouterGroup

	// 跨域，如需跨域可以打开下面的注释
	Router.Use(middleware.Cors()) // 直接放行全部跨域请求

	// system Router 初始化
	{
		systemRouter.UserRouter.InitUserRouter(Router)
		systemRouter.DashBoardRouter.InitDashBoardRouter(Router)
		systemRouter.SysArticleRouter.InitSysArticleRouter(Router)
	}

	global.GB_ROUTERS = Router.Routes()

	return Router
}
